<?php
	/*
	 *    Copyright 2009 OneProfession
	 *
	 *     Licensed under the Apache License, Version 2.0 (the "License");
	 *     you may not use this file except in compliance with the License.
	 *     You may obtain a copy of the License at
	 *
	 *          http://www.apache.org/licenses/LICENSE-2.0
	 *
	 *      Unless required by applicable law or agreed to in writing, software
	 *      distributed under the License is distributed on an "AS IS" BASIS,
	 *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	 *      See the License for the specific language governing permissions and
	 *      limitations under the License.
	 */

	/*
	 * Include UAS template classes
	 */
	require_once("connectors/inherit.class.php");

	/*
	 * Include UAS class and object definitions
	 */
	require_once("uas_includes/uas_definitions.php");
	
	/*
	 * Include UAS configuration file
	 */
	require_once("uas_includes/uas_config.php");
	
	/*
	 * Include UAS sessions runtime
	 */
	require_once("uas_includes/uas_sessions.php");
	
	/*
	 * Include UAS database access class
	 */
	require_once("uas_includes/uas_database.php");
	
	/*
	 * Include all required connectors
	 */
	// Include Master connector Class
	require_once("connectors/" . $uas_config->master->type . ".php");
	// Include Aux connector Class
	foreach($uas_config->aux as $key => $value){
		try{
			require_once("connectors/" . $value->type . ".php");
		} catch(Exception $e){
			echo "<p>Failed to include: " . $value->type . ";</p>";
		}
	}
	
	/*
	 * Define UAS Class
	 * 
	 * This class is to be instantiated by any scripts requiring UAS use.
	 * The class includes all functions needed to cleanly handle UAS authentication
	 * including data synchronisation, login, logout.
	 */
	class UAS{
		
		var $master;
		var $auxs = Array();
		
		
		/*
		 *  UAS Constructor
		 */
		function __construct($uc){
			// collect up parts and configure them
			$master = new $uc->master->type;
		}
		
		/*
		 * Login user with given credentials
		 */
		function Login($user, $password, $op_html = false){
			//authenticate against master
				//if successful authenticate against remainder
				// redirect to authenticate form before redirect
					//authenticate form should check for ajaxs. if needed, do
					// at end (when ajax = "") show confirmation message and timed redirect
				//if unsuccessful redirect to login page with messages
				
				//op_html means create own default page rather than redirect
		}
		
		function Logout($id){}
		
		function Update_User(int $id, $values){
			//update all sources with
			//threads from keys, values from data pairs
			//for user id
		}
		
		function Update_User_From($id, $connector, $threads = ""){
			//update selected user, from selected threads
			//from the connector given as a source
		}
		
		function Get_User_Data($id, $threads, $source = ""){
			//get (from master as default) the threads for the given user
		}
		
		function Synchronise_User($id){
			//synchronise the selected user
			//not sure what this should mean yet - perhaps use master as source to populate
			//all auxs, creating user if necessary. Perhaps after initial registration.
		}
		
		function Synchronise_All(){
			//find all missing users, or missing threads etc and update all
			//from... each?
		}
		
		function Create_User($threadvalues){
			return $user_identifier;
		}
		
		function Delete_User($user_identifier){
			
		}
		
	}
	
?>